/*
 * pl_comm.h
 *
 *  Created on: 2023年2月23日
 *      Author: Lw
 */

#ifndef SRC_PL_COMM_PL_COMM_H_
#define SRC_PL_COMM_PL_COMM_H_
#include "gnc_addit.h"
#include "ff.h"
/*定义相机1预处理算法参数存储文件*/
#define EMMC_CAM1_PRPE_PARAM_FILE "0:/PARAM1.BIN"
/*定义相机2预处理算法参数存储文件*/
#define EMMC_CAM2_PRPE_PARAM_FILE "0:/PARAM2.BIN"
/* 像素坏点存储文件 */
/* 像素点Mask大小 */
#define EMMC_DeadPixelMask_ROW      6422
#define EMMC_DeadPixelMask_COLUMN   9600
#define EMMC_DeadPixelMask_ARRAY    (EMMC_DeadPixelMask_ROW * EMMC_DeadPixelMask_COLUMN)
#define EMMC_DeadPixelMask_SIZE     ((EMMC_DeadPixelMask_ARRAY / 8) + 4)
/* 相机1坏点Mask */
#define EMMC_DeadPixelMask_1_FILE_NAME       "0:/Mask1.BIN"
/* 相机1出厂坏点Mask */
#define EMMC_DeadPixelMask_INIT_1_FILE_NAME  "0:/Mask1_init.BIN"
/* 相机2坏点Mask */
#define EMMC_DeadPixelMask_2_FILE_NAME       "0:/Mask2.BIN"
/* 相机2出厂坏点Mask */
#define EMMC_DeadPixelMask_INIT_2_FILE_NAME  "0:/Mask2_init.BIN"

typedef struct{
	u8 Flat_Dark_process_en;
	u16 block_size_0;
	u16 block_size_1;
	u16 blcok0_Nmax0;
	u16 blcok1_Nmax1;
	u16 blcok_Nmin;
	u16 corner_cnt;
	u16 atomosphere_thresh;
	u16 max_cfs_npix;
	u16 binarized_thresh;
	u32 saturated_thresh;
	u16 object_thresh;
	u16 min_streak_npix;
	u16 max_streak_npix;
	u8 porosity_grade;
	u8 Target_detection_num;
	u8 sub_filtering_en;
	u8 atomosphere_mask_en;
	u8 fill_defect_mask_en;
	u16 bright_region_thresh;
	u16 flat_dark_dn_offset;
	u16 sita3_value;
	u16 cali_norm_value;
	u8 scale_factor;
	u16 length_width_ratio;
	u16 corr_coef_thresh0;
	u16 corr_coef_thresh1;

}S_PREP_PARAM;

typedef struct{
	u8 cm1SaveFlag;
	u8 cm2SaveFlag;
}S_PREP_PARAM_SAVE;
S_PREP_PARAM_SAVE s_CamPrepFlag;
S_PREP_PARAM s_Cam1PrepParam;
S_PREP_PARAM s_Cam2PrepParam;


void SetFpgaWorkMode(u8 ucNum, u32 uiValue);
void SetFpgaExposureTime(u8 ucNum, u32 uiValue);
void SetFpgaPicNum(u8 ucNum, u32 uiValue);
void SetFpga3CEachPic(u8 ucNum, u32 uiValue);
void SetFpgaGain(u8 ucNum, u32 uiValue);
void SetFpgaShotTimeLapse(u8 ucNum, u32 uiValue);
void SetFpgaShot(u8 ucNum);
void SetFpgaTime(u32 uiSecond);
u32 ReadPlRecvImageNum(u8 ucNum);
u32 ReadPlSendImageNum(u8 ucNum);
u32 ReadPlDDRPicNum(u8 ucNum);
u32 ReadPlProcessNum(u8 ucNum);
u32 ReadPlObjNum(u8 ucNum);
u32 ReadlvdsPackNum(void);
u32 ReadSTime(void);
u32 ReadMsTime(void);
void SetCMA_Prep_Para(u8 Command, u8 *puacData, u8 Num);
void WriteAdditData(u8 port, u16 num, S_tAdditData* AdditDataPtr);
u8 ReadCaliState(u8 port, u8 type);
u32 ReadPlLockedState(void);
FRESULT plCommInit(void);
void PixelMask_Config(void);
void prepParamSave(void);


u32 Read_Flat_Dark_process(u8 ucNum);
u32 Read_block_size_0(u8 ucNum);
u32 Read_block_size_1(u8 ucNum);
u32 Read_blcok0_Nmax0(u8 ucNum);
u32 Read_blcok1_Nmax1(u8 ucNum);
u32 Read_blcok_Nmin(u8 ucNum);
u32 Read_corner_cnt(u8 ucNum);
u32 Read_atomosphere_thresh(u8 ucNum);
u32 Read_max_cfs_npix(u8 ucNum);
u32 Read_binarized_thresh(u8 ucNum);
u32 Read_saturated_thresh(u8 ucNum);
u32 Read_object_thresh(u8 ucNum);
u32 Read_min_streak_npix(u8 ucNum);
u32 Read_max_streak_npix(u8 ucNum);
u32 Read_porosity_grade(u8 ucNum);
u32 Read_Target_detection_num(u8 ucNum);
u32 Read_sub_filtering_en(u8 ucNum);
u32 Read_atomosphere_mask_en(u8 ucNum);
u32 Read_fill_defect_mask_en(u8 ucNum);
u32 Read_bright_region_thresh(u8 ucNum);
u32 Read_flat_dark_dn_offset(u8 ucNum);
u32 Read_3sita_value(u8 ucNum);
u32 Read_cali_norm_value(u8 ucNum);
u32 Read_scale_factor(u8 ucNum);
u32 Read_length_width_ratio(u8 ucNum);
u32 Read_corr_coef_thresh0(u8 ucNum);
u32 Read_corr_coef_thresh1(u8 ucNum);
u32 Read_pl_run_status(u8 ucNum);
#endif /* SRC_PL_COMM_PL_COMM_H_ */
